<template>
  <div class="user-login login-bg">
    <div class="user-login--content">
      <!--      <img :src="logo" alt="">-->
      <a-form class="form" ref="formRef" :model="formState" :rules="rules" v-bind="layout">
        <a-form-item class="form-item" has-feedback name="username">
          <a-input class="input" v-model:value="formState.username" type="text" @keyup.enter="onSubmit()" placeholder="请输入用户名"
                   autocomplete="off" allow-clear />
        </a-form-item>
        <a-form-item class="form-item" has-feedback name="password">
          <a-input class="input" v-model:value="formState.password" type="password" @keyup.enter="onSubmit()" placeholder="请输入登录密码"
                   autocomplete="off" allow-clear />
        </a-form-item>
        <a-button class="login-button mt-24" type="primary" size="large" block @click="onSubmit()">登录</a-button>
      </a-form>
    </div>
  </div>
</template>

<script lang="ts">
  import { defineComponent, reactive, ref, UnwrapRef } from 'vue'
  import { useRoute, useRouter } from 'vue-router'
  import logo from '@/assets/image/logo.png'

  interface FormState {
    username: string;
    password: string;
  }

  export default defineComponent({
    setup() {
      const formRef = ref()
      const $route = useRoute()
      const $router = useRouter()

      const redirect: any = decodeURIComponent(($route.query.redirect as any) || '/welcome')

      const formState: UnwrapRef<FormState> = reactive({
        username: '',
        password: ''
      })

      const rules = {
        username: [{ required: true, message: '请输入账号', trigger: 'blur' }],
        password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
      }

      const layout = {
        labelCol: { span: 0 },
        wrapperCol: { span: 24 }
      }

      const resetForm = () => {
        formRef.value.resetFields()
      }

      const onSubmit = () => {
        formRef.value.validate().then(() => {
          $router.replace({
            path: redirect || 'welcome'
          })
        })
      }
      return {
        redirect,
        formRef,
        formState,
        rules,
        layout,
        logo,
        resetForm,
        onSubmit
      }
    },
    mounted() {
      // this.$testFn('hahah');
    }
  })
</script>

<style lang="less" scoped>
  .user-login {
    display: flex;
    flex-direction: column;
    //align-items: center;
    justify-content: center;
    height: 100%;
    background: url(@/assets/image/login-bg.jpeg) no-repeat;
    background-size: 100% 100%;
    padding-left: 55%;

    &--content {
      width: 384px;
      height: 320px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      align-content: center;
      background-color: #fff;
      padding: 40px;
      box-shadow: 0 4px 22px 3px rgba(2, 15, 58, 0.51);
      border-radius: 10px;

      img {
        width: auto;
        height: 40px;
        margin-bottom: 30px;
      }

      .form {
        width: 100%;
      }
    }

    &--footer {
      text-align: center;
      padding: 24px 50px;
      font-size: 12px;

      &.record-number {
        color: rgba(255, 255, 255, 0.75);

        &:hover {
          color: #fff;
        }
      }
    }

    .login-footer {
      color: #ffffff;
      position: fixed;
      width: 100%;
      line-height: 40px;
      left: 0;
      bottom: 0;
      text-align: center;
    }
  }

  //.login-bg {
  //  display: flex;
  //  align-items: center;
  //  justify-content: center;
  //
  //  //&::before {
  //  //  position: absolute;
  //  //  top: 0;
  //  //  left: 0;
  //  //  width: 100%;
  //  //  height: 100%;
  //  //  margin-left: -48%;
  //  //  background-image: url(@/assets/svg/login-bg.svg);
  //  //  background-position: 100%;
  //  //  background-repeat: no-repeat;
  //  //  background-size: auto 100%;
  //  //  content: '';
  //  //}
  //}

</style>
